<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <input type="file" id="fileUpload">
  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  <script>
    /* 
      1. post query参数
      2. post 发送文件
      3. 另一种写法
    */
    axios.post('http://myjavascript.cn/leo', "user=leo&pass=123456").then(res => {
      console.log('响应结果：', res.data);
    })
    var fileUpload = document.getElementById('fileUpload')
    fileUpload.onchange = function () {
      const fm = new FormData()
      fm.append('上传文件', this.files[0])
      // axios.post('http://myjavascript.cn/setFiles', fm).then(res => {
      //   console.log('响应结果：', res.data);
      // })
      axios({
        "method": 'post',
        "url": 'http://myjavascript.cn/setFiles',
        "data": fm
      }).then(res => {
        console.log('响应结果3：', res.data);
      })
    }
    
  </script>
</body>

</html>